import {
  BadRequestException,
  Controller,
  Get,
  Inject,
  ParseEnumPipe,
  Query,
} from '@nestjs/common';
import { StatisticService } from './statistic.service';
import { RequireLogin, RequirePermission } from 'src/decorator/index.decorator';

@Controller('statistic')
@RequireLogin()
@RequirePermission('show_statistic')
export class StatisticController {
  @Inject(StatisticService)
  private readonly statisticService: StatisticService;

  @Get('bookingCount')
  async userBookingCount(
    @Query('startTime') startTime: string,
    @Query('endTime') endTime: string,
    @Query(
      'type',
      new ParseEnumPipe(['user', 'room'], {
        exceptionFactory: () =>
          new BadRequestException(`type 必须为 user 或 room`),
      }),
    )
    type: 'user' | 'room',
  ) {
    return this.statisticService.bookingCount(startTime, endTime, type);
  }
}
